<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2006/12/29 13:46:14 $)
// $RCSfile: setup.php,v $ : $Revision: 1.4 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Called when the module is to be installed
*/
function _news_install($action, $page = '') {
	global $_SWIFT, $__LANG;

	if ($action == "getpages")
	{
		return "1";
	} else if ($action == "buildpage") {
		$_SWIFT["query"]["create"]["news"] = "CREATE TABLE ". TABLE_PREFIX ."news (
																				newsid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				tgroupid INT UNSIGNED NOT NULL DEFAULT '0',
																				staffid INT UNSIGNED NOT NULL DEFAULT '0',
																				newstype ENUM('public', 'private') NOT NULL DEFAULT 'public',
																				subject VARCHAR(255) NOT NULL DEFAULT '',
																				emailsubject VARCHAR(255) NOT NULL DEFAULT '',
																				description TEXT,
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				expiry INT UNSIGNED NOT NULL DEFAULT '0',
																				edited SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																				editedstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																				editeddateline INT UNSIGNED NOT NULL DEFAULT '0',
																				totalcomments INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (newsid),
																				KEY news1 (tgroupid, newstype, expiry, dateline),
																				KEY news2 (newstype, expiry, dateline)
																			);";

		$_SWIFT["query"]["create"]["newsdata"] = "CREATE TABLE ". TABLE_PREFIX ."newsdata (
																				newsdataid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				newsid INT UNSIGNED NOT NULL DEFAULT '0',
																				contents MEDIUMTEXT,
																				PRIMARY KEY (newsdataid),
																				KEY newsdata1 (newsid)
																			);";

		$_SWIFT["query"]["create"]["newssubscribers"] = "CREATE TABLE ". TABLE_PREFIX ."newssubscribers (
																				newssubscriberid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																				tgroupid INT UNSIGNED NOT NULL DEFAULT '0',
																				userid INT UNSIGNED NOT NULL DEFAULT '0',
																				email VARCHAR(255) NOT NULL DEFAULT '',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				validated SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (newssubscriberid),
																				KEY newssubscribers1 (tgroupid, validated),
																				UNIQUE KEY (email)
																			);";

		$_SWIFT["query"]["create"]["newsverihash"] = "CREATE TABLE ". TABLE_PREFIX ."newsverihash (
																				newsverihashid VARCHAR(32) NOT NULL DEFAULT '',
																				newssubscriberid INT UNSIGNED NOT NULL DEFAULT '0',
																				hash VARCHAR(50) NOT NULL DEFAULT '',
																				dateline INT UNSIGNED NOT NULL DEFAULT '0',
																				PRIMARY KEY (newsverihashid),
																				KEY newsverihash1 (newssubscriberid),
																				KEY newsverihash2 (hash)
																			);";

		$_SWIFT["query"]["insert"]["settings"][0] = "INSERT INTO `". TABLE_PREFIX ."settings`(`section`, `vkey`, `data`) VALUES('registeredmodules', '". MODULE_NEWS ."', '1')";
	}
}

/**
* Uninstall Routine
*/
function _news_uninstall()
{
	global $_SWIFT;

	$_SWIFT["query"]["drop"]["news"] = "DROP TABLE `". TABLE_PREFIX ."news`;";

	$_SWIFT["query"]["drop"]["newsdata"] = "DROP TABLE `". TABLE_PREFIX ."newsdata`;";

	$_SWIFT["query"]["drop"]["newssubscribers"] = "DROP TABLE `". TABLE_PREFIX ."newssubscribers`;";

	$_SWIFT["query"]["drop"]["newsverihash"] = "DROP TABLE `". TABLE_PREFIX ."newsverihash`;";

	$_SWIFT["query"]["delete"]["settings"][0] = "DELETE FROM `". TABLE_PREFIX ."settings` WHERE `section` = 'registeredmodules' AND `vkey` = '". MODULE_NEWS ."';";
}
?>